<!DOCTYPE html>
<html lang="zh-CN" color-mode=light>


<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>SpringBootAdmin 学习探究 - 树朾的开源技术分享</title>
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="google" content="notranslate" />
  <meta name="keywords" content="开源, 分享">
  <meta name="description" content="SpringBootAdmin 是一个监控工具，旨在以...">
  <meta name="author" content="scwang90">
  <link rel="icon" href="/images/icons/favicon.ico">
  
  
  
  
  

  
<link rel="stylesheet" href="/css/style.css">


  
    
<link rel="stylesheet" href="https://at.alicdn.com/t/font_1445822_p6ry5n7lrr.css">

  

  
    
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">

  

  
    
      
        
        
<link rel="stylesheet" href="https://cdn.bootcss.com/highlight.js/9.18.1/styles/xcode.min.css" name="highlight-style" mode="light">

      
        
        
<link rel="stylesheet" href="https://cdn.bootcss.com/highlight.js/9.18.1/styles/solarized-dark.min.css" name="highlight-style" mode="dark">

      
  

  <script>
    var CONFIG = window.CONFIG || {};
    var ZHAOO = window.ZHAOO || {};
    CONFIG = {
      isHome: false,
      fancybox: true,
      pjax: false,
      loading: {
        gif: '/images/theme/loading.gif',
        lottie: ''
      },
      lazyload: {
        enable: true,
        only_post: 'false',
        loading: {
          gif: '/images/theme/loading.gif',
          lottie: ''
        }
      },
      donate: {
        enable: false,
        alipay: '/images/donate/pay_alipay.jpg',
        wechat: '/images/donate/pay_wxpay.jpg',
        tencent: '/images/donate/pay_tencent.jpg'
      },
      galleries: {
        enable: true
      },
      fab: {
        enable: true,
        always_show: false
      },
      carrier: {
        enable: true
      },
      daovoice: {
        enable: false
      },
      preview: {
        background: {
          default: '',
          api: ''
        },
        motto: {
          default: '我在开了灯的床头下，想问问自己的心啊。',
          typing: true,
          api: 'https://v2.jinrishici.com/one.json',
          data_contents: '["data","content"]'
        },
      },
      qrcode: {
        enable: true,
        type: 'url',
        image: 'https://pic.izhaoo.com/weapp-code.jpg',
      },
      toc: {
        enable: true
      },
      scrollbar: {
        type: 'default'
      },
      notification: {
        enable: false,
        delay: 4500,
        list: '',
        page_white_list: '',
        page_black_list: ''
      },
      search: {
        enable: false,
        path: ''
      }
    }
  </script>

  

  

<meta name="generator" content="Hexo 6.2.0"></head>

<body class="lock-screen">
  <div class="loading" id="loading"></div>
  
    


  <nav class="navbar">
    <div class="left">
      
        <i class="iconfont iconhome j-navbar-back-home"></i>
      
      
        <i class="iconfont iconqrcode j-navbar-qrcode"></i>
      
      
        <i class="iconfont iconmoono" id="color-toggle" color-toggle="light"></i>
      
      
    </div>
    <div class="center">SpringBootAdmin 学习探究</div>
    <div class="right">
      <i class="iconfont iconmenu j-navbar-menu"></i>
    </div>
    
      <div id="qrcode-navbar"></div>
    
  </nav>

  
  

<nav class="menu">
  <div class="menu-container">
    <div class="menu-close">
      <i class="iconfont iconbaseline-close-px"></i>
    </div>
    <ul class="menu-content"><li class="menu-item">
        <a href="/ " class="underline "> 首页</a>
      </li><li class="menu-item">
        <a href="/galleries/ " class="underline "> 摄影</a>
      </li><li class="menu-item">
        <a href="/archives/ " class="underline "> 归档</a>
      </li><li class="menu-item">
        <a href="/tags/ " class="underline "> 标签</a>
      </li><li class="menu-item">
        <a href="/categories/ " class="underline "> 分类</a>
      </li><li class="menu-item">
        <a href="/about/ " class="underline "> 关于</a>
      </li></ul>
    
      <div class="menu-copyright"><p>Powered by <a target="_blank" href="https://github.com/scwang90">scwang90</a>  |  Theme - <a target="_blank" href="https://github.com/izhaoo/hexo-theme-zhaoo">zhaoo</a></p> <p><a target="_blank" href="http://beian.miit.gov.cn/"><span>黔ICP备2021004317号-1</span></a><span>  |  </span><a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;"><img class="lazyload" data-original="/images/icons/icon-filing.png" src="https://www.beian.gov.cn/img/new/gongan.png"/> <span> 贵公网安备 52010202002539号</span></a></p></div>
    
  </div>
</nav>
  <main id="main">
  <div class="article-wrap">
    
      <div class="row container container-lg">
        <div class="col-xl-2"></div>
        <div class="col-xl-8"><article class="article">
  <div class="wrap">
    <section class="head">
  <img   class="lazyload" data-original="/images/theme/post-image.jpg" src=""  draggable="false">
  <div class="head-mask">
    <h1 class="head-title">SpringBootAdmin 学习探究</h1>
    <div class="head-info">
      <span class="post-info-item"><i class="iconfont iconcalendar"></i>七月 11, 2024</span>
      
      <span class="post-info-item"><i class="iconfont iconfont-size"></i>6348</span>
    </div>
  </div>
</section>
    <section class="main">
      <section class="content article-entry">
        
          
            <p>SpringBootAdmin 是一个监控工具，旨在以良好且易于访问的方式可视化 Spring Boot Actuators 提供的信息</p>
          
        
        <h2 id="概念说明"><a href="#概念说明" class="headerlink" title="概念说明"></a>概念说明</h2><p>SpringBootAdmin 是基于 spring-boot-actuator 实现的。spring-boot-actuator 负责基础的监控统计，<br>SpringBootAdmin 负责传输和展示监控统计结果。</p>
<p>SpringBootAdmin 分为客户端和服务端：spring-boot-admin-server 和 spring-boot-admin-client。<br>spring-boot-admin-server 是一个完整的项目，可以统管多个 spring-boot-admin-client，有完整的管理页面，<br>登录部分需要 spring-boot-security 实现，且需要手动引入和配置相关认证信息。</p>
<p>spring-boot-admin-client 只是一个内嵌在业务系统中的组件，它负责连接注册到 spring-boot-admin-server，<br>使得 spring-boot-admin-server 可以看到业务系统的监控统计。它只是负责注册连接 spring-boot-admin-server，<br>真正的监控统计需要 spring-boot-admin-server 反向调用业务系统的 spring-boot-actuator 相关接口，<br>且 spring-boot-actuator 的接口必须是免登录状态，不然 spring-boot-admin-server 展示的页面为空状态。</p>
<p>spring-boot-admin-server 和 spring-boot-admin-client 也可以同时集成在一个业务系统中，只要把两端的配置整合即可。</p>
<blockquote>
<p><em>注意</em>：SpringBootAdmin 只是 Spring 的第三方库，而其依赖的 spring-boot-actuator 是官方库</p>
</blockquote>
<h2 id="配置-spring-boot-admin-server"><a href="#配置-spring-boot-admin-server" class="headerlink" title="配置 spring-boot-admin-server"></a>配置 spring-boot-admin-server</h2><ol>
<li><p>maven 依赖配置</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 基础Web依赖 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- spring-boot-admin-server 依赖 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>de.codecentric<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-admin-starter-server<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 登录部分需要 spring-boot-security 实现 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-security<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
<li><p>spring 配置文件</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">8000</span></span><br><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">application:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">spring-admin</span></span><br><span class="line">  <span class="comment"># SpringBootAdmin 的原理是 先启动 SpringBootAdminServer 使用上面的 $&#123;server.port:8000&#125; 端口</span></span><br><span class="line">  <span class="comment"># 浏览器可以访问 http://localhost:8000 访问登录 SpringBootAdminServer</span></span><br><span class="line">  <span class="comment"># SpringBootAdminServer 是一个被动等待 SpringBootAdminClient 的连接</span></span><br><span class="line">  <span class="comment"># SpringBootAdminClient 需要配置 http://localhost:8000 注册地址和 admin:admin 的账号信息</span></span><br><span class="line">  <span class="attr">boot:</span></span><br><span class="line">    <span class="attr">admin:</span></span><br><span class="line">      <span class="comment"># 改变 SpringBootAdminServer 的注册地址</span></span><br><span class="line">      <span class="comment"># SpringBootAdminClient 配置的注册地址也要跟着修改</span></span><br><span class="line">      <span class="attr">context-path:</span> <span class="string">/</span></span><br><span class="line">  <span class="comment"># SpringBootAdminServer 的登录认证要结合 SpringSecurity 一起使用</span></span><br><span class="line">  <span class="comment"># 要在Java代码 SecurityConfig 中</span></span><br><span class="line">  <span class="comment"># 配置 SpringBootAdminServer 的相关资源连接免登录如 /assets/**</span></span><br><span class="line">  <span class="comment"># 配置 SpringBootAdminServer 认证相关页面 /login /logout</span></span><br><span class="line">  <span class="attr">security:</span></span><br><span class="line">    <span class="attr">user:</span></span><br><span class="line">      <span class="attr">name:</span> <span class="string">admin</span></span><br><span class="line">      <span class="attr">password:</span> <span class="string">admin</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>Java配置登录认证</p>
</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@EnableWebSecurity</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">SecurityConfig</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> String adminContextPath;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> AdminServerProperties adminServer;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">SecurityConfig</span><span class="params">(AdminServerProperties adminServerProperties)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.adminContextPath = adminServerProperties.getContextPath();</span><br><span class="line">        <span class="built_in">this</span>.adminServer = adminServerProperties;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> SecurityFilterChain <span class="title function_">filterChain</span><span class="params">(HttpSecurity httpSecurity)</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line">        <span class="type">SavedRequestAwareAuthenticationSuccessHandler</span> <span class="variable">successHandler</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">SavedRequestAwareAuthenticationSuccessHandler</span>();</span><br><span class="line">        successHandler.setTargetUrlParameter(<span class="string">&quot;redirectTo&quot;</span>);</span><br><span class="line">        <span class="comment">// adminServer.path(&quot;/&quot;) 和 adminContextPath + &quot;/&quot; 等效</span></span><br><span class="line">        successHandler.setDefaultTargetUrl(adminContextPath + <span class="string">&quot;/&quot;</span>);</span><br><span class="line">        successHandler.setDefaultTargetUrl(adminServer.path(<span class="string">&quot;/&quot;</span>));</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> httpSecurity</span><br><span class="line">                .headers().frameOptions().disable()</span><br><span class="line">                .and()</span><br><span class="line">                .authorizeRequests()</span><br><span class="line">                .antMatchers(adminContextPath + <span class="string">&quot;/assets/**&quot;</span></span><br><span class="line">                    , adminContextPath + <span class="string">&quot;/login&quot;</span></span><br><span class="line">                    , <span class="string">&quot;/actuator&quot;</span></span><br><span class="line">                    , <span class="string">&quot;/actuator/**&quot;</span></span><br><span class="line">                ).permitAll()</span><br><span class="line">                .anyRequest().authenticated()</span><br><span class="line">                .and()</span><br><span class="line">                .formLogin().loginPage(adminContextPath + <span class="string">&quot;/login&quot;</span>)</span><br><span class="line">                .successHandler(successHandler).and()</span><br><span class="line">                .logout().logoutUrl(adminContextPath + <span class="string">&quot;/logout&quot;</span>)</span><br><span class="line">                .and()</span><br><span class="line">                .httpBasic().and()</span><br><span class="line">                .csrf()</span><br><span class="line">                .disable()</span><br><span class="line">                .build();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="配置-spring-boot-admin-client"><a href="#配置-spring-boot-admin-client" class="headerlink" title="配置 spring-boot-admin-client"></a>配置 spring-boot-admin-client</h2><ol>
<li>maven 依赖配置<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- spring-boot-admin-client （内部已经包含了 spring-boot-actuator ） --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>de.codecentric<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-admin-starter-client<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- ... 其他业务系统依赖 --&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
<li>spring 配置文件<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">application:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">spring-app</span></span><br><span class="line">  <span class="attr">boot:</span></span><br><span class="line">    <span class="attr">admin:</span></span><br><span class="line">      <span class="comment"># SpringBootAdmin 监控的原理是先启动一个 SpringBootAdminServer 暴露地址 http://127.0.0.1:8000/admin</span></span><br><span class="line">      <span class="comment"># 然后 由 SpringBootAdminClient 向 SpringBootAdminServer 登录并注册服务</span></span><br><span class="line">      <span class="attr">client:</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line">        <span class="comment"># SpringBootAdminServer 的用户名和密码</span></span><br><span class="line">        <span class="attr">username:</span> <span class="string">admin</span></span><br><span class="line">        <span class="attr">password:</span> <span class="string">admin</span></span><br><span class="line">        <span class="comment"># 连接SpringBootAdminServer的地址</span></span><br><span class="line">        <span class="comment"># 但是注册成功后，展示监控内容时，SpringBootAdminServer 会反向请求本服务的 /actuator 接口</span></span><br><span class="line">        <span class="comment"># 所以 /actuator 的接口应该是免登录的，否则注册成功后 SpringBootAdminServer 展示的监控内容为空</span></span><br><span class="line">        <span class="attr">url:</span> <span class="string">http://127.0.0.1:8000/admin</span></span><br><span class="line">        <span class="attr">instance:</span></span><br><span class="line">          <span class="comment"># 向 SpringBootAdminServer 注册的服务名称</span></span><br><span class="line">          <span class="attr">name:</span> <span class="string">$&#123;spring.application.name&#125;</span></span><br><span class="line">          <span class="attr">prefer-ip:</span> <span class="literal">true</span></span><br><span class="line">          <span class="attr">service-host-type:</span> <span class="string">IP</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 提供详细信息，可以在 SpringBootAdminServer 中看得到</span></span><br><span class="line"><span class="attr">info:</span></span><br><span class="line">  <span class="comment"># app 是一个字典，内部的 key 可以随意定义</span></span><br><span class="line">  <span class="attr">app:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">app-info</span></span><br><span class="line">    <span class="attr">version:</span> <span class="number">1.0</span></span><br><span class="line">    <span class="attr">test:</span> <span class="string">test</span></span><br><span class="line">    <span class="comment"># 随意的 Key 值</span></span><br><span class="line">    <span class="attr">scwang:</span> <span class="string">name</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># spring-boot-actuator 的配置信息</span></span><br><span class="line"><span class="attr">management:</span></span><br><span class="line">  <span class="attr">info:</span></span><br><span class="line">    <span class="attr">env:</span></span><br><span class="line">      <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line">  <span class="attr">endpoint:</span></span><br><span class="line">    <span class="attr">loggers:</span></span><br><span class="line">      <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line">    <span class="attr">health:</span></span><br><span class="line">      <span class="attr">show-details:</span> <span class="string">always</span></span><br><span class="line">  <span class="attr">endpoints:</span></span><br><span class="line">    <span class="attr">enabled-by-default:</span> <span class="literal">true</span></span><br><span class="line">    <span class="attr">web:</span></span><br><span class="line">      <span class="comment"># spring-boot-actuator 监控接口前缀</span></span><br><span class="line">      <span class="attr">base-path:</span> <span class="string">/actuator</span></span><br><span class="line">      <span class="attr">exposure:</span></span><br><span class="line">        <span class="attr">include:</span> <span class="string">&#x27;*&#x27;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="client-和-server-单实例部署"><a href="#client-和-server-单实例部署" class="headerlink" title="client 和 server 单实例部署"></a>client 和 server 单实例部署</h2><p>经过试验验证，他们是可以混合在一起部署的，把 client 和 server 的配置混合在一起再微调就行</p>
<ol>
<li>spring 配置调整</li>
</ol>
<p>配置只给出了特别要修改的部分</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">8000</span></span><br><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">boot:</span></span><br><span class="line">    <span class="attr">admin:</span></span><br><span class="line">      <span class="comment"># 改变 SpringBootAdminServer 的注册地址，防止和业务系统的功能冲突</span></span><br><span class="line">      <span class="comment"># 修改后的地址为 http://localhost:8000/admin</span></span><br><span class="line">      <span class="comment"># SpringBootAdminClient 配置的注册地址也要改为 http://localhost:8000/admin</span></span><br><span class="line">      <span class="attr">context-path:</span> <span class="string">admin</span></span><br><span class="line">      <span class="comment"># SpringBootAdmin 监控的原理是先启动一个 SpringBootAdminServer 暴露地址 http://127.0.0.1:8000/admin</span></span><br><span class="line">      <span class="comment"># 然后 由 SpringBootAdminClient 向 SpringBootAdminServer 登录并注册服务</span></span><br><span class="line">      <span class="attr">client:</span></span><br><span class="line">        <span class="comment"># 连接SpringBootAdminServer的地址</span></span><br><span class="line">        <span class="comment"># 但是注册成功后，展示监控内容时，SpringBootAdminServer 会反向请求本服务的 /actuator 接口</span></span><br><span class="line">        <span class="comment"># 所以 /actuator 的接口应该是免登录的，否则注册成功后 SpringBootAdminServer 展示的监控内容为空</span></span><br><span class="line">        <span class="attr">url:</span> <span class="string">http://127.0.0.1:8000/admin</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li>Java 代码调整</li>
</ol>
<p>如果业务系统使用的认证框架不是 spring-boot-security，则需要另作修改，这里也无法给出配置代码</p>

      </section>
      <section class="extra">
        
          <ul class="copyright">
  
    <li><strong>本文作者：</strong>scwang90</li>
    <li><strong>本文链接：</strong><a href="https://blog.scwang90.cn/2024/07/11/spring-boot-admin-study/index.html" title="https:&#x2F;&#x2F;blog.scwang90.cn&#x2F;2024&#x2F;07&#x2F;11&#x2F;spring-boot-admin-study&#x2F;index.html">https:&#x2F;&#x2F;blog.scwang90.cn&#x2F;2024&#x2F;07&#x2F;11&#x2F;spring-boot-admin-study&#x2F;index.html</a></li>
    <li><strong>版权声明：</strong>本分享所有文章均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" title="BY-NC-SA" target="_blank" rel="noopener">BY-NC-SA</a> 许可协议，转载请注明出处！</li>
  
</ul>
        
        
        
  <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/admin/" rel="tag">admin</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spring/" rel="tag">spring</a></li></ul> 

        
  <nav class="nav">
    <a href="/2024/07/11/breakthrough-element-ui/"><i class="iconfont iconleft"></i>ElementUI 难点攻克</a>
    <a href="/2024/05/23/spring-boot-config-study/">SpringBoot 配置文件加载源码学习探究<i class="iconfont iconright"></i></a>
  </nav>

      </section>
      
    </section>
  </div>
</article></div>
        <div class="col-xl-2">
          
            
  <aside class="toc-wrap">
    <h3 class="toc-title">文章目录：</h3>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A6%82%E5%BF%B5%E8%AF%B4%E6%98%8E"><span class="toc-text">概念说明</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE-spring-boot-admin-server"><span class="toc-text">配置 spring-boot-admin-server</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE-spring-boot-admin-client"><span class="toc-text">配置 spring-boot-admin-client</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#client-%E5%92%8C-server-%E5%8D%95%E5%AE%9E%E4%BE%8B%E9%83%A8%E7%BD%B2"><span class="toc-text">client 和 server 单实例部署</span></a></li></ol>
  </aside>

          
        </div>
      </div>
    
  </div>
</main>
  

<footer class="footer">
  <div class="footer-social"><a 
        href="tencent://message/?Menu=yes&uin=283371828 "
        target="_blank"
        class="footer-social-item"
        onMouseOver="this.style.color= '#12B7F5'" 
        onMouseOut="this.style.color='#33333D'">
          <i class="iconfont  iconQQ "></i>
      </a><a 
        href="javascript:; "
        target="_blank"
        class="footer-social-item"
        onMouseOver="this.style.color= '#09BB07'" 
        onMouseOut="this.style.color='#33333D'">
          <i class="iconfont  iconwechat-fill "></i>
      </a><a 
        href="https://github.com/scwang90 "
        target="_blank"
        class="footer-social-item"
        onMouseOver="this.style.color= '#9f7be1'" 
        onMouseOut="this.style.color='#33333D'">
          <i class="iconfont  icongithub-fill "></i>
      </a><a 
        href="mailto:scwang90@hotmail.com "
        target="_blank"
        class="footer-social-item"
        onMouseOver="this.style.color=#FF3B00" 
        onMouseOut="this.style.color='#33333D'">
          <i class="iconfont  iconmail"></i>
      </a></div>
  
    <div class="footer-copyright"><p>Powered by <a target="_blank" href="https://github.com/scwang90">scwang90</a>  |  Theme - <a target="_blank" href="https://github.com/izhaoo/hexo-theme-zhaoo">zhaoo</a></p> <p><a target="_blank" href="http://beian.miit.gov.cn/"><span>黔ICP备2021004317号-1</span></a><span>  |  </span><a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;"><img class="lazyload" data-original="/images/icons/icon-filing.png" src="https://www.beian.gov.cn/img/new/gongan.png"/> <span> 贵公网安备 52010202002539号</span></a></p></div>
  
</footer>
  
      <div class="fab fab-plus">
    <i class="iconfont iconplus"></i>
  </div>
  
  
  
  <div class="fab fab-up">
    <i class="iconfont iconcaret-up"></i>
  </div>
  
  
  
    
<script src="/js/color-mode.js"></script>

  
  
</body>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>





  
<script src="https://cdn.bootcdn.net/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"></script>




  
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>






  
<script src="https://cdn.bootcdn.net/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>




<script src="/js/utils.js"></script>
<script src="/js/script.js"></script>







  <script>
    (function () {
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
      } else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
      }
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>













</html>